package www.openteam.com.model.realtime;

import android.support.annotation.NonNull;

import java.util.List;

import www.openteam.com.OTApplication;
import www.openteam.com.base.BaseModel;
import www.openteam.com.bean.TakeDeliverGoods;
import www.openteam.com.exception.ApiException;
import www.openteam.com.subscribe.CommonSubscriber;
import www.openteam.com.transformer.CommonTransformer;

/**
 * Created by kylin on 2017/1/4.
 */

public class TakeGoodsModel extends BaseModel {

    private boolean isQuery = false;

    public boolean queryTDeliverGoods(@NonNull String rdsno,
                                      @NonNull String custid,
                                      long startDate,
                                      long endDate,
                                      String stype,
                                      String moreCom,
                                      int userId,
                                      String jMark,
                                      @NonNull int PageSize, @NonNull final
                                      TakeGoodsOnListener takeGoodsOnListener) {
        httpApiService.queryTDeliverGoods(rdsno,custid,startDate,endDate,stype,moreCom,userId,jMark,PageSize)
                .compose(new CommonTransformer<TakeDeliverGoods>())
                .subscribe(new CommonSubscriber<TakeDeliverGoods>(OTApplication.getmContext()) {
                               @Override
                               public void onNext(TakeDeliverGoods takeDeliverGoods) {
                                   isQuery = true;
                                   takeGoodsOnListener.queryDGSuccess(takeDeliverGoods.getData());
                               }

                               @Override
                               protected void onError(ApiException e) {
                                   super.onError(e);
                                    isQuery =false;
                                   takeGoodsOnListener.queryDGFail(e.message);
                               }
                           });
        return isQuery;
    }

    //通过接口产生信息回调
    public interface TakeGoodsOnListener {

        void queryDGSuccess(List<TakeDeliverGoods.DataBean> data);

        void queryDGFail(String failMsg);
    }


}

